<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Options extends MY_Controller {
	function __construct(){
		parent::__construct();
	}

  function admin_contactus(){
    $_post = $this->input->post();
    if(empty($_post["submit"])){
      $result = self::getOption("contactus");
      $this->_assign("content",$result);
      $this->_fetch("form_contactus");
    }else{
      $result = self::setOption("contactus",$_post["content"]);
      redirect(base_url("admin/options/contactus"));
    }
    
  }

  private function getOption($key = ""){
    if(!empty($key)){
      $where["where"]["key"] = $key;
      $result = $this->optionsModel->get($where);
    }else{
      $result = $this->optionsModel->get();
    }
    return $result[0];
  }

  private function setOption($key = "", $value = ""){
    if(empty($key)){
      return FALSE;
    }
    $where["where"]["key"] = $key;
    $getResult = $this->optionsModel->get($where);
    if(!empty($getResult)){
      $data["id"] = $getResult[0]["id"];
    }
    $data["key"] = $key;
    $data["value"] = $value;
    $result = $this->optionsModel->add($data);
    return $result;
  }
}